package com.ms.game.itembox.container;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.ms.game.common.container.BasicBinUtil;
import com.ms.game.itembox.ItemSimpleData;
import com.xpec.c4.service.module.common.ItemInfoManager;

/**
 * 道具權重列表
 * 
 * @author TW15012
 *
 */
public class ItemRollGroupListUtil extends BasicBinUtil {
	private static ItemRollGroupList bin;

	/** log4j object */
	private static final Log log = LogFactory.getLog(ItemRollGroupListUtil.class);

	@Override
	public void onBinLoad(Object binInstance) {
		bin = (ItemRollGroupList) binInstance;

	}
	
	public static void checkItemRallGroupListItem(){
		// 掃一遍所有群組中的道具資料
		HashMap<String, HashMap<String, ArrayList<ItemRollGroupData>>> DataMap = bin.getDataMap();
		for (Map.Entry<String, HashMap<String, ArrayList<ItemRollGroupData>>> dataEntry : DataMap.entrySet()) {
			HashMap<String, ArrayList<ItemRollGroupData>> groupDataMap = dataEntry.getValue();
			for (Map.Entry<String, ArrayList<ItemRollGroupData>> groupEntry : groupDataMap.entrySet()) {
				ArrayList<ItemRollGroupData> itemList = groupEntry.getValue();
				for (ItemRollGroupData item : itemList) {
					// 不是水晶就要檢查 id 是否存在
					if (!item.getItemid().equals(ItemSimpleData.CRYSTAL_ID)) {
						// 指定的道具 id 不存在
						if (!ItemInfoManager.getInstance().isItemExist(item.getItemid())) {
							if (log.isErrorEnabled()) {
								log.error("itemId [" + item.getItemid() + "] is invalid in "
										+ bin.getClass().getSimpleName() + ".bin \\ " + dataEntry.getKey()
										+ " \\ " + groupEntry.getKey(), new RuntimeException());
							}
						}
					}
				} // loop itemList
			} // loop groupDataMap
		} // loop DataMap		
	}
}
